﻿@{
    ViewBag.Title = "WorkTypeIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
 <script>
     var keyValue = "",_TypeId="";

     $(function () {
         initControl();
         GetTree();
         GetGrid();
     })
     function initControl() {
         //layout布局
         $('#layout').layout({
             applyDemoStyles: true,
             onresize: function () {
                 $(window).resize()
             }
         });
         //resize重设(表格、树形)宽高
         $(window).resize(function (e) {
             window.setTimeout(function () {
                 $('#gridTable').setGridWidth(($('.gridPanel').width()));
                 $("#gridTable").setGridHeight($(window).height() - 181.5);
             }, 200);
             e.stopPropagation();
         });
     }
     function GetTree() {
         var item = {
             height: $(window).height() - 55.5,
             url: "../../PropertyManage/CS_DeviceMaintance/GetWorkTypeTreeJson",
             onnodeclick: function (item) {
                 _TypeId = item.id;
                 $('#btn_Search').trigger("click");
             }
         };
         //初始化
         $("#itemTree1").treeview(item);
     }
     function GetGrid()
     {
         $gridTable = $("#gridTable");
         var queryJson = {
             keyValue: keyValue,
             Type: _TypeId,
             condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
             keyword: $("#txt_Keyword").val(),
         }
         $gridTable.jqGrid({
             url: "../../PropertyManage/CS_DeviceMaintance/GetWorkTypeList",
             postData: { queryJson: JSON.stringify(queryJson) },
             datatype: "json",
             height: $(window).height()   -115,
             autowidth: true,
             colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "编号", name: "Code", index: "Code", width: 100, align: "center", sortable: false },
                { label: "名称", name: "Name", index: "Name", width: 200, align: "center", sortable: false },
                { label: "描述", name: "Memo", index: "Memo", width: 100, align: "center", sortable: false }

             ],
             viewrecords: true,
             treeGrid: true,
             treeGridModel: "nested",
             ExpandColumn: "Name",
             rowNum: "all",
             rownumbers: true,

             onSelectRow: function (id) {
                  
             },
             gridComplete: function () {
                  
             }
         });
         //查询条件
         $("#queryCondition .dropdown-menu li").click(function () {
             var text = $(this).find('a').html();
             var value = $(this).find('a').attr('data-value');
             $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
         });
         //查询事件
         $("#btn_Search").click(function () {
             var queryJson = {
                 keyValue: keyValue,
                 Type: _TypeId,
                 condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                 keyword: $("#txt_Keyword").val(),
             }
             $gridTable.jqGrid('setGridParam', {
                 postData: { queryJson: JSON.stringify(queryJson) }
             }).trigger('reloadGrid');
         });
         //查询回车
         $('#txt_Keyword').bind('keypress', function (event) {
             if (event.keyCode == "13") {
                 $('#btn_Search').trigger("click");
             }
         });
     }

     function btn_add()
     {
         dialogOpen({
             id: "WorkTypeForm",
             title: '添加项目类型',
             url: '/PropertyManage/CS_DeviceMaintance/TypeForm',
             width: "800px",
             height: "500px",
             callBack: function (iframeId) {
                 top.frames["WorkTypeForm"].AcceptClick();
             }
         })
     }
 
     function btn_edit() {
         var keyValue = $("#gridTable").jqGridRowValue("Id");
         if (checkedRow(keyValue)) {
             dialogOpen({
                 id: "WorkTypeForm",
                 title: '修改信息',
                 url: '/PropertyManage/CS_DeviceMaintance/TypeForm?keyValue=' + keyValue,
                 width: "800px",
                 height: "500px",
                 callBack: function (iframeId) {
                     top.frames["WorkTypeForm"].AcceptClick();
                 }
             });
         }
     }
     
     function btn_delete() {
         var keyValue = $("#gridTable").jqGridRowValue("Id");
         if (checkedRow(keyValue)) {
             $.RemoveForm({
                 url: "../../PropertyManage/CS_DeviceMaintance/RemoveWorkTypeForm",
                 param: { keyValue: keyValue },
                 success: function (data) {
                      
                 }
             })
         }
     }
 </script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px; text-align:center;">项目类型</div>
             <div id="itemTree1"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr><td style="padding-left: 2px;">
                                <div class="btn-group" id="queryCondition">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">筛选条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编号</a></li>
                                        <li><a data-value="Name">名称</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>

                        </tr>

                    </table>
                </div>

                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload(); "><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    @*<script>$('.toolbar').authorizeButton()</script>*@
                </div>
            </div>

            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>